#include "Debug_Test.h"

#include "misc/Debug.h"
#include "Poco/Exception.h"
#include <iostream>
#include <stdio.h>
#include <fstream>
/*********************************************************/
std::string DebugTest::name()
{
	return("Debug");
}
/*********************************************************/
bool DebugTest::runUnitTests()
{
	bool result = true;

	if ( !singleInstanceTest() ) result = false;
	if ( !logDumpTest() ) result = false;

	return( result ) ;
}
/*********************************************************/
bool DebugTest::logDumpTest()
{
	std::cout << "Running: logDumpTest()";
	Debug& debug = Debug::Instance();
	std::string 	file = "Debug_Log_Testfile.txt";

	remove(file.c_str());		// Make sure the file is gone prior to the dump
	debug << "File Log Dump Test" << std::endl;
	debug.log(file.c_str());
	
	std::ifstream	ifile(file.c_str());
	if ( ifile.is_open() ) {	// File got created!
		ifile.close();
		remove(file.c_str());
		std::cout << "... success!" << std::endl;
		return( true );
	} else {
		remove(file.c_str());
		std::cout << "... failed! Did not find debug output log file!" << std::endl;
		return( false );
	}
}
/*********************************************************/
bool DebugTest::singleInstanceTest()
{
	std::cout << "Running: singleInstanceTest()";
	Debug& e = Debug::Instance();
	Debug& ee = Debug::Instance();

	if ( &e == &ee ) {
		std::cout << "... success!" << std::endl;
		return( true );
	} else {
		std::cout << "... Failed!" << std::endl;
		return( false );
	}		
}
